import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CommentApi } from '#/api/wedding/comment';

import { z } from '#/adapter/form';
import {
    DICT_Wedding_TYPE,
    getDictOptions,
    getRangePickerDefaultProps,
} from '#/utils';

/** 编辑评论的表单（管理员使用，只能编辑部分字段） */
export function useEditFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      componentProps: {
        type: 'hidden',
      },
      dependencies: {
        show: false,
      },
    },
    {
      fieldName: 'content',
      label: '评论内容',
      rules: 'required',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入评论内容',
        rows: 4,
        maxlength: 1000,
        showCount: true,
      },
    },
    {
      fieldName: 'rating',
      label: '评分',
      rules: 'required',
      component: 'Rate',
      componentProps: {
        allowHalf: false,
      },
    },
    {
      fieldName: 'status',
      label: '评论状态',
      component: 'RadioGroup',
      componentProps: {
        options: [
          { label: '待审核', value: 'pending' },
          { label: '已通过', value: 'approved' },
          { label: '已拒绝', value: 'rejected' },
        ],
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
  ];
}

/** 新增/修改的表单（完整字段） */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      componentProps: {
        type: 'hidden',
      },
      dependencies: {
        show: false,
      },
    },
    {
      fieldName: 'targetType',
      label: '评论目标类型',
      rules: 'required',
      component: 'Select',
      componentProps: {
        placeholder: '请选择评论目标类型',
        options: [
          { label: '婚纱', value: 'dress' },
          { label: '摄影师', value: 'photographer' },
          { label: '化妆师', value: 'makeupartist' },
          { label: '套餐', value: 'package' },
        ],
      },
    },
    {
      fieldName: 'targetId',
      label: '评论目标ID',
      rules: 'required',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入评论目标ID',
      },
    },
    {
      fieldName: 'userId',
      label: '用户ID',
      rules: 'required',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入用户ID',
      },
    },
    {
      fieldName: 'userName',
      label: '用户名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入用户名称',
      },
    },
    {
      fieldName: 'userAvatar',
      label: '用户头像',
      component: 'Input',
      componentProps: {
        placeholder: '请输入用户头像URL',
      },
    },
    {
      fieldName: 'content',
      label: '评论内容',
      rules: 'required',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入评论内容',
        rows: 4,
      },
    },
    {
      fieldName: 'rating',
      label: '评分',
      rules: 'required',
      component: 'Rate',
      componentProps: {
        allowHalf: true,
      },
    },
    {
      fieldName: 'images',
      label: '评论图片',
      component: 'Upload',
      componentProps: {
        multiple: true,
        accept: 'image/*',
        listType: 'picture-card',
      },
    },
    {
      fieldName: 'parentId',
      label: '父评论ID',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入父评论ID（回复时使用）',
      },
    },
    {
      fieldName: 'replyTo',
      label: '回复的评论ID',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入回复的评论ID',
      },
    },
    {
      fieldName: 'replyToUser',
      label: '回复的用户名',
      component: 'Input',
      componentProps: {
        placeholder: '请输入回复的用户名',
      },
    },
    {
      fieldName: 'status',
      label: '评论状态',
      component: 'RadioGroup',
      componentProps: {
        options: [
          { label: '待审核', value: 'pending' },
          { label: '已通过', value: 'approved' },
          { label: '已拒绝', value: 'rejected' },
          { label: '已删除', value: 'deleted' },
        ],
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'targetType',
      label: '评论目标类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        placeholder: '请选择评论目标类型',
        options: [
          { label: '婚纱', value: 'dress' },
          { label: '摄影师', value: 'photographer' },
          { label: '化妆师', value: 'makeupartist' },
          { label: '套餐', value: 'package' },
        ],
      },
    },
    {
      fieldName: 'targetId',
      label: '评论目标ID',
      component: 'InputNumber',
      componentProps: {
        allowClear: true,
        placeholder: '请输入评论目标ID',
      },
    },
    {
      fieldName: 'userName',
      label: '用户名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入用户名称',
      },
    },
    {
      fieldName: 'rating',
      label: '评分',
      component: 'Select',
      componentProps: {
        allowClear: true,
        placeholder: '请选择评分',
        options: [
          { label: '1星', value: 1 },
          { label: '2星', value: 2 },
          { label: '3星', value: 3 },
          { label: '4星', value: 4 },
          { label: '5星', value: 5 },
        ],
      },
    },
    {
      fieldName: 'status',
      label: '评论状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        placeholder: '请选择评论状态',
        options: [
          { label: '待审核', value: 'pending' },
          { label: '已通过', value: 'approved' },
          { label: '已拒绝', value: 'rejected' },
          { label: '已删除', value: 'deleted' },
        ],
      },
    },
    {
      fieldName: 'keyword',
      label: '关键词',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '搜索评论内容',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<CommentApi.Comment>['columns'] {
  return [
//     {
//       field: 'id',
//       title: 'ID',
//       width: 80,
//     },
    {
      field: 'targetType',
      title: '评论目标',
      width: 100,
      formatter: ({ cellValue }) => {
        const typeMap = {
          dress: '婚纱',
          photographer: '摄影师',
          makeupartist: '化妆师',
          package: '套餐',
        };
        return typeMap[cellValue] || cellValue;
      },
    },
    {
      field: 'targetId',
      title: '目标ID',
      width: 80,
    },
    {
      field: 'userName',
      title: '用户名称',
      width: 120,
    },
    {
      field: 'rating',
      title: '评分',
      width: 120,
      slots: { default: 'rating' },
    },
    {
      field: 'content',
      title: '评论内容',
      showOverflow: 'tooltip',
    },
    {
      field: 'status',
      title: '状态',
      width: 100,
      slots: { default: 'status' },
    },
    {
      field: 'likeCount',
      title: '点赞数',
      width: 80,
    },
    {
      field: 'replyCount',
      title: '回复数',
      width: 80,
    },
    {
      field: 'createTime',
      title: '创建时间',
      width: 160,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 250,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
